package com.dhecp.project.purchase.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.dhecp.project.purchase.domain.*;
import com.dhecp.project.purchase.mapper.PaymentMapper;
import com.dhecp.project.purchase.mapper.PurchasePlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.RandomValueUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.core.utils.ReflectUtils;
import com.dhecp.project.common.domain.ModuleNID;
import com.dhecp.project.common.domain.RecordCheck;
import com.dhecp.project.common.domain.UpdateDeleted;
import com.dhecp.project.common.domain.UpdateFlow;
import com.dhecp.project.common.service.impl.BaseModuleServiceImpl;
import com.dhecp.project.purchase.mapper.PurchaseOrderMapper;
import com.dhecp.project.purchase.mapper.PurchaseOrderSonMapper;
import com.dhecp.project.purchase.service.PurchaseOrderService;
import com.dhecp.project.storage.domain.PurchaseStorage;
import com.dhecp.project.storage.mapper.PurchaseStorageMapper;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * @program: kjecp
 * @description: 采购订单服务层
 * @author: hlf
 * @create: 2022-08-22 10:00
 */
@Service
public class PurchaseOrderServiceImpl extends BaseModuleServiceImpl implements PurchaseOrderService {


    @Autowired
    private PurchaseOrderMapper purchaseMapper;
    @Autowired
    private PurchaseOrderSonMapper sonMapper;
    @Autowired
    private PurchaseStorageMapper storageMapper;
    @Autowired
    private PurchasePlanMapper planMapper;
    @Autowired
    private PaymentMapper paymentMapper;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;

    /**
     * @Description: 查询前一单NID、BID
     * @Param: [params] nid 必要参数：当前 单据编码
     * @return: com.dhecp.common.core.domain.AjaxResult  (data.nid 前一单NID， data.bid 前一单BID)
     * @Author: hlf
     * @date: 2022-05-09 10:08
     */
    @Override
    public AjaxResult queryLastNid(Map<String, Object> params) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (params.get("nid") == null || params.get("nid") == "") {
            params.put("nid", "0");
        }
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        ModuleNID moduleNID = purchaseMapper.selectLastNid(params);
        if (moduleNID == null) {
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfirstnid"), TypeUtils.mapToJson(dataMap).toString());
        }
        dataMap.put("nid", moduleNID.getNid().toString());
        dataMap.put("bid", moduleNID.getBid().toString());
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), TypeUtils.mapToJson(dataMap).toString());
    }


    /**
     * @Description: 查询后一单NID、BID
     * @Param: [params] nid 必要参数：当前 单据编码
     * @return: com.dhecp.common.core.domain.AjaxResult  (data.nid 后一单NID， data.bid 后一单BID)
     * @Author: hlf
     * @date: 2022-05-09 10:09
     */
    @Override
    public AjaxResult queryNextNid(Map<String, Object> params) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (params.get("nid") == null || params.get("nid") == "" || "0".equals(params.get("nid").toString())) {
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfinallynid"), TypeUtils.mapToJson(dataMap).toString());
        }
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        ModuleNID moduleNID = purchaseMapper.selectNextNid(params);
        if (moduleNID == null) {
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfinallynid"), TypeUtils.mapToJson(dataMap).toString());
        }
        dataMap.put("nid", moduleNID.getNid().toString());
        dataMap.put("bid", moduleNID.getBid().toString());
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), TypeUtils.mapToJson(dataMap).toString());
    }


    /**
     * @Description: 查询指定单nid的首记录
     * @Param: [params]
     * @return: com.dhecp.project.hr.domain.PurchaseOrder
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @Override
    public PurchaseOrder queryFirstRecord(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        return purchaseMapper.selectFirstRecordByNid(params);
    }


    /**
     * 获取采购订单（根据采购订单号）
     * @param bid 采购订单号
     * @return
     * @throws Exception
     */
    @Override
    public PurchaseOrder selectOneByBid(String bid) {
        return purchaseMapper.findByBID(bid);
    }

    /**
     * @Description: 查询指定单nid的整单录
     * @Param: [params] nid 必要参数：当前 单据编码
     * @return: java.util.List<com.dhecp.project.hr.domain.PurchaseOrder>
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @Override
    public List<PurchaseOrder> queryListByNid(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        return purchaseMapper.selectByNid(params);
    }

    /**
     * @Description: 根据Guid 查询子件数据
     * @Param: [pGuid]
     * @return: java.util.List<com.dhecp.project.purchase.domain.PurchaseOrderSon>
     * @Author: hlf
     * @date: 2022-08-22 13:48
     */
    @Override
    public List<PurchaseOrderSon> querySonList(String pNid) throws Exception {
        return sonMapper.querySonList(pNid);
    }

    /**
     * @Description: 查询
     * @Param: [params]
     * @return: java.util.List<com.dhecp.project.hr.domain.PurchaseOrder>
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @Override
    public List<PurchaseOrder> queryList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));    //常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        PageUtils.startPageStronger();
        return purchaseMapper.select(params);
    }
    /**
     * @Description: 导出查询
     * @Param: [params]
     * @return: java.util.List<com.dhecp.project.hr.domain.PurchaseOrder>
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @Override
    public List<PurchaseOrder> queryExportList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));    //常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        PageUtils.startPageStronger();
        return purchaseMapper.queryExportList(params);
    }

    /**
     * @Description: 查询
     * @Param: [params]
     * @return: java.util.List<com.dhecp.project.hr.domain.PurchaseOrder>
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @Override
    public List<PurchaseOrder> selectAllOrder(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));    //常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        PageUtils.startPage();
        return purchaseMapper.selectAllOrder2(params);
    }

    /**
     * @Description: 查询已选择的数据
     * @Param: [params]
     * @return: java.util.List<com.dhecp.project.system.domain.SysUserInfoSimple>
     * @Author: hlf
     * @date: 2022-08-18 17:14
     */
    @Override
    public List<PurchaseOrder> querySelectList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));        //常规查询条件SQL语句
        if (params.containsKey("selIdList")) {
            params.put("selIdList", params.get("selIdList").toString().split(","));
        }
        if (params.get("field") == null || params.get("field") == "") {
            String orderBy = "bid asc";
            PageUtils.startPageOrder(orderBy);
        } else {
            PageUtils.startPage();
        }
        return purchaseMapper.querySelectList(params);
    }

    /**
     * @Description: 根据母件获取之间 (多条
     * @Param: [fBm]
     * @return: java.util.List<com.dhecp.project.business.domain.ProductBasisComponent>
     * @Author: hlf
     * @date: 2022-08-18 17:14
     */
    @Override
    public List<PurchaseOrderSon> querySonListByPNid(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));        //常规查询条件SQL语句
        if (params.get("field") == null || params.get("field") == "") {
            String orderBy = "pNid asc";
            PageUtils.startPageOrder(orderBy);
        } else {
            PageUtils.startPage();
        }
        return sonMapper.querySonListByPNid(params);
    }

    /**
     * @Description: 根据BID获取退货数据
     * @Param: [BID]
     * @return: java.util.List<com.dhecp.project.business.domain.PurchaseOrder>
     * @Author: hlf
     * @date: 2022-08-18 17:14
     */
    @Override
    public List<Refund> querySonListByBID(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));        //常规查询条件SQL语句
        if (params.get("field") == null || params.get("field") == "") {
            String orderBy = "iid asc";
            PageUtils.startPageOrder(orderBy);
        } else {
            PageUtils.startPage();
        }
        return purchaseMapper.querySonListByBID(params);
    }


    /**
     * @Description: 保存
     * @Param: [params] moduleTable 必要参数：功能唯一标识
     * @Param: [params] infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     * @Param: [params] infoItems 必要参数：对应实体类的json格式字符串
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-05-09 10:10
     */
    @SuppressWarnings("unchecked")
    @Override
    public AjaxResult saveData(Map<String, Object> params) {
        params.put("businessEntity", new PurchaseOrder());

        AjaxResult ajaxResult = this.saveDataBase(params);
        if (!"0".equals(ajaxResult.get("code").toString())) {
            throw new RuntimeException(ajaxResult.get("msg").toString());
        }

        String resNid = "0";
        Map<String, Object> infoMap = (Map<String, Object>) ajaxResult.get("infoMap");
        List<PurchaseOrder> businessDataList = (List<PurchaseOrder>) ajaxResult.get("businessDataList");
        List<PurchaseOrderSon> onSonData = JSON.parseArray(params.get("sonData").toString(), PurchaseOrderSon.class);


        List<RecordCheck> guidMapList = purchaseMapper.findRecords(infoMap.get("nid").toString());
        Map<String, Object> guidMap = new HashMap<String, Object>();
        if (!guidMapList.isEmpty()) {
            if (infoMap.get("newNid") != null && "1".equals(infoMap.get("newNid").toString())) { //单号重复验证
                throw new RuntimeException(MessageUtils.message("module.error.retry"));
            }
            for (RecordCheck recordCheck : guidMapList) {
                if (recordCheck != null && recordCheck.getGuid() != null) {
                    guidMap.put(recordCheck.getGuid().toString(), "1");
                }
            }
        }

        if (businessDataList == null || businessDataList.size() == 0) {
            resNid = "0";
        } else {
            resNid = infoMap.get("nid").toString();
            for (PurchaseOrder businessData : businessDataList) {
                String guid = "";
                if (businessData.getGuid() == null) {
                    guid = RandomValueUtils.getGUID();
                    businessData.setGuid(guid);
                } else {
                    guid = businessData.getGuid().toString();
                }

                for (String field : infoMap.keySet()) { //遍历非网格字段，并赋值到实体中
                    Object fieldValue = infoMap.get(field);
                    ReflectUtils.setValue(businessData, field, fieldValue);
                }

                if (guidMap.get(guid) == null) {
                    purchaseMapper.insert(businessData);
                    for (PurchaseOrderSon item : onSonData
                    ) {
                        item.setGuid(RandomValueUtils.getGUID());
                        item.setCreateTime(new Date());
                        item.setpGuid(businessData.getGuid());
                        sonMapper.insert(item);
                    }
                } else {
                    businessData.setUpdateTime(new Date());
                    purchaseMapper.update(businessData);
                    sonMapper.delete(businessData.getGuid());
                    for (PurchaseOrderSon item : onSonData
                    ) {
                        item.setGuid(RandomValueUtils.getGUID());
                        item.setCreateTime(new Date());
                        item.setpGuid(businessData.getGuid());
                        sonMapper.insert(item);
                    }
                    guidMap.remove(guid);
                }

            }
        }

        if (!guidMap.isEmpty()) {
            for (String guid : guidMap.keySet()) {
                purchaseMapper.delete(guid);
            }
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), resNid);
    }


	@Override
	public AjaxResult updateAliPromotionId(String bid, String aliPromotionId) {
		PurchaseOrder purchaseOrder = purchaseMapper.findByBID(bid);
		purchaseOrder.setAliPromotionId(aliPromotionId);
		
		purchaseMapper.update(purchaseOrder);
		
		return AjaxResult.success("操作成功");
	}

    /**
     * @Description: 删除
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult deleteData(Map<String, Object> params) {
        List<PurchaseOrder> businessDataList = JSON.parseArray(params.get("infoItems").toString(), PurchaseOrder.class);
        if (businessDataList == null || businessDataList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.jsontoentyerror"));
        }
        for (PurchaseOrder businessData : businessDataList) {

            List<PurchaseOrder> purchaseOrders = purchaseMapper.findByPlanID(businessData.getPlanID());//删除订单本体 --采购订单删除的数据按照相同采购计划单全部删除
            if (purchaseOrders.size()>0){
                for (PurchaseOrder order:purchaseOrders
                ) {
                    if(order.getAliOrderNumber()!=null && !Objects.equals(order.getAliOrderNumber(), "")){
                        return AjaxResult.error("已创建1688订单，不能删除");
                    }
                    List<PurchaseOrderSon> purchaseOrderSonList = sonMapper.querySonList(order.getNid());//删除订单子表
                    for (PurchaseOrderSon item : purchaseOrderSonList
                    ) {
                        sonMapper.delete(item);
                    }

                    purchaseMapper.delete(order);
                }
            }

            PurchasePlan purchasePlan = planMapper.findByBID(businessData.getPlanID());//修改采购计划的订单状态
            purchasePlan.setOrderState("订单已删除");
            planMapper.updateOrderState(purchasePlan);

        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
    }

    /**
     * @Description: 修改删除标志（预留）
     * @Param: [params] infoItems 必要参数：对应实体类的json格式字符串（仅需 guid 和 deleted）
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult updateDeleted(Map<String, Object> params) {
        List<UpdateDeleted> updateDeletedList = JSON.parseArray(params.get("infoItems").toString(), UpdateDeleted.class);
        if (updateDeletedList == null || updateDeletedList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.jsontoentyerror"));
        }
        for (UpdateDeleted updateDeleted : updateDeletedList) {
            purchaseMapper.updateDeleted(updateDeleted);
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
    }

    /**
     * @Description: 流转  —— 添加流程任务、修改流程状态及生效标志
     * @Param: [params] tableDataId 必要参数：单据编码（nid）
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult updateFlowGo(Map<String, Object> params) {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        String nid = "0";
        if (params.get("tableDataId") == null || params.get("tableDataId") == "") {
            return AjaxResult.error(MessageUtils.message("module.error.lack", "单据编码【tableDataId】"));
        } else {
            nid = params.get("tableDataId").toString();
        }
        params.put("nid", nid);
        List<PurchaseOrder> businessDataList = purchaseMapper.selectByNid(params);
        if (businessDataList == null || businessDataList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.nodata"));
        } else {
            infoMap.put("cid", businessDataList.get(0).getCid());
            infoMap.put("bUser", businessDataList.get(0).getbUser());
            infoMap.put("bDept", businessDataList.get(0).getbDept());
            infoMap.put("procInstId", businessDataList.get(0).getProcInstId());
            infoMap.put("activeFlow", businessDataList.get(0).getActiveFlow());
            infoMap.put("createTime", businessDataList.get(0).getCreateTime());
            params.put("infoMap", TypeUtils.mapToJson(infoMap).toString());
            params.put("activeFlowOld", businessDataList.get(0).getActiveFlow());
        }

        //流程处理公共方法，返回单据（流转、回退等）后的流程状态信息
        if (params.get("optType") == null || params.get("optType") == "") {
            params.put("optType", "go");
        }
        UpdateFlow updateFlow = new UpdateFlow();
        updateFlow = this.FlowDealBase(params);

        for (PurchaseOrder businessData : businessDataList) {
            updateFlow.setGuid(businessData.getGuid().toString());
            purchaseMapper.updateFlow(updateFlow);
        }

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), nid);
    }

    /**
     * @Description: 退回  —— 添加流程任务、修改流程状态及生效标志
     * @Param: [params] tableDataId 必要参数：单据编码（nid）
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult updateFlowBack(Map<String, Object> params) {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        String nid = "0";
        if (params.get("tableDataId") == null || params.get("tableDataId") == "") {
            return AjaxResult.error(MessageUtils.message("module.error.lack", "单据编码【tableDataId】"));
        } else {
            nid = params.get("tableDataId").toString();
        }
        params.put("nid", nid);
        List<PurchaseOrder> businessDataList = purchaseMapper.selectByNid(params);
        if (businessDataList == null || businessDataList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.nodata"));
        } else {
            infoMap.put("cid", businessDataList.get(0).getCid());
            infoMap.put("bUser", businessDataList.get(0).getbUser());
            infoMap.put("bDept", businessDataList.get(0).getbDept());
            infoMap.put("procInstId", businessDataList.get(0).getProcInstId());
            infoMap.put("activeFlow", businessDataList.get(0).getActiveFlow());
            infoMap.put("createTime", businessDataList.get(0).getCreateTime());
            params.put("infoMap", TypeUtils.mapToJson(infoMap).toString());
            params.put("activeFlowOld", businessDataList.get(0).getActiveFlow());
        }

        //流程处理公共方法，返回单据（流转、回退等）后的流程状态信息
        if (params.get("optType") == null || params.get("optType") == "") {
            params.put("optType", "back");
        }
        UpdateFlow updateFlow = new UpdateFlow();
        updateFlow = this.FlowDealBase(params);

        for (PurchaseOrder businessData : businessDataList) {
            updateFlow.setGuid(businessData.getGuid().toString());
            purchaseMapper.updateFlow(updateFlow);
        }

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), nid);
    }


    /**
     * 修改审核状态
     *
     * @param infoItems
     * @return
     * @author DH-Xxj
     */
    @Override
    public AjaxResult updateType(Map<String, Object> params) {
        List<PurchaseOrder> purchaseOrders = JSON.parseArray(params.get("infoItems").toString(), PurchaseOrder.class);
        int x = 0;
        String msg = "";
        for (PurchaseOrder item : purchaseOrders
        ) {

            Map<String, Object> param2 = new HashMap<String, Object>();
            param2.put("guid",item.getGuid());
            PurchaseOrder order = purchaseMapper.findById(param2);


            if (!item.getState().equals("待审核")){
                List<PurchaseOrderSon> purchaseOrderSonList = sonMapper.querySonList(order.getNid());
                if (params.get("type").equals("1")){
                    for (PurchaseOrderSon sonData:purchaseOrderSonList) {//判断SKU是否相等 SKU2为下单后获取的实际SKU属性
                        if (sonData.getsKU2() == null) sonData.setsKU2("");
                        if (sonData.getsKU() == null) sonData.setsKU("");
                        if (!sonData.getsKU().equals(sonData.getsKU2())) return AjaxResult.error("订单："+ order.getBid()+"SKU属性不符，请重新铺货！");
                    }
                }

                if (item.getAliState() != null && !Objects.equals(item.getAliState(), "")){
                    item.setUpdateTime(new Date());
                    purchaseMapper.update(item);
                }else {
                    x ++;
                }
                if (x>0){
                    msg = x+"条数据审核失败，请确认订单是否创建！";
                }
            }else{

                Payment payment = paymentMapper.queryOrderId(order.getBid());
                if (payment != null){
                    return AjaxResult.error("订单："+ payment.getOrderID()+"已生成付款单，不可退回");
                }else{
                    purchaseMapper.update(item);
                }
            }

        }
//        return AjaxResult.success(MessageUtils.message("操作成功!"+x+"条数据执行失败!"+msg));
        return AjaxResult.success("操作成功!"+msg);
    }

    /**
     * 修改物流信息
     *
     * @param infoItems
     * @return
     * @author DH-Xxj
     */
    @Override
    public AjaxResult saveLogistics(Map<String, Object> params) {
        try {
            PurchaseOrder purchaseOrders = JSON.parseObject(params.get("infoItems").toString(), PurchaseOrder.class);
//            purchaseOrders.setUpdateTime(new Date());
            purchaseOrders.setWarehouseTime(new Date());
            purchaseMapper.update(purchaseOrders);
            purchaseMapper.createOrder(purchaseOrders);
            if (purchaseOrders.getWarehouse() != null && !Objects.equals(purchaseOrders.getWarehouse(), "")) {
                Map<String, Object> params2 = new HashMap<String, Object>();
                params2.put("bid", purchaseOrders.getWarehouse());
                params2.put("moduleTable", ModuleTable.PURCHASE_STORAGE);
                params2.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params2));    //常规查询条件SQL语句
                List<PurchaseStorage> purchaseStorages = storageMapper.select(params2);
                for (PurchaseStorage item2 : purchaseStorages
                ) {
                    item2.setTrackingNumber(purchaseOrders.getAliLogisticsCode());
                    item2.setPlace(purchaseOrders.getAliPlace());
                    storageMapper.updateOrderState(item2);
                }
            }
        } catch (Exception e) {
            return AjaxResult.error(String.valueOf(e));
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
    }




    /**
     * @Description: 根据BID获取退货数据
     * @Param: [BID]
     * @return: java.util.List<com.dhecp.project.business.domain.PurchaseOrder>
     * @Author: hlf
     * @date: 2022-08-18 17:14
     */
    @Override
    public List<PurchaseOrder> isAllAudit(String[] ids) throws Exception {
        return purchaseMapper.isAllAudit(ids);
    }

}